<?php
require '../include/library.inc.php';
require '../include/admin_login.inc.php';
require '../include/paging.inc.php';

$sql = "SELECT
			s.school_id,
			s.name AS school_name,
			s.published,
			s.featured,
			s.order_number,
			c.name AS city,
			c.state
		FROM
		  	schools AS s,
			cities AS c
		WHERE
			s.city_id = c.city_id
		  ";
		  
if (!isset($_GET['sort'])) $_GET['sort'] = 1;
if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 5;

$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(5=>"Order", 2=>"School Name", 6=>"City"), 30);
$result = $paging->query();
	
	head_admin("Schools");
?>
		
			<?php if ($_SESSION['message']) { ?>
			<div class="message green">
				<?=$_SESSION['message']?>
			</div>
			<?php unset($_SESSION['message']); } ?>
		
			
            
            <div class="topbuttons">
            	 Order by: <?=$paging->displayNext()?> <?=$paging->displayNext()?> <?=$paging->displayNext()?> &nbsp; &nbsp; &nbsp; &nbsp;
                 <a class="add" href="school_new.php">Add New School</a> 
            </div>
            
            <h3>Schools (<?=$paging->count()?>)</h3>
            
            <table id="listing" width="100%" cellpadding="0" cellspacing="0">
			<thead>
				<tr>
                    <td>School Name</td>
                    <td>Order</td>
                    <td>Featured</td>
                    <td>Options</td>
				</tr>
			</thead>
			<tbody>
			<?php
	  
			  $i=1;
			  while ($row = mysql_fetch_object($result)) {				  
			?>
                <tr class="<?=(($i%2)?"none":"zebra")?>">
                    
                    <td>
                        <a href="school_edit.php?school_id=<?=$row->school_id?>" title="Edit"><?=$row->school_name?></a>,
                        <?=$row->city?>, <?=$row->state?>
                    </td>
                    
                    <td class="sort">
                        <?php if ($i != 1 && $_GET['sortBy'] == 5 && $_GET['sort'] == 1) { ?>
                        <a name="Up" class="sorting_up" title="Up" href="school_direction.php?school_id=<?=$row->school_id?>&direction=1"></a>
                        <?php } ?>							
                        <?php if ($i != ($paging->count()) && $_GET['sortBy'] == 5  && $_GET['sort'] == 1) { ?>
                        <a name="Down" class="sorting_down" title="Down" href="school_direction.php?school_id=<?=$row->school_id?>&direction=-1"></a>
                        <?php } ?>
                        &nbsp;<!--ie6 bug-->
                    </td>
                    
                    <td class="icons">
                    	
                        <?php if ($row->featured) { ?>
                         <a href="school_featured.php?school_id=<?=$row->school_id?>&featured=0" class="turn_on" name="turn_on" title="Featured"></a>
                        <?php } else { ?> 
                         <a href="school_featured.php?school_id=<?=$row->school_id?>&featured=1" class="turn_off" name="turn_off" title="Make Featured"></a>
                        <?php } ?>
                        
                    </td>
                    
                    <td class="icons">
                    	
                        <?php if ($row->published) { ?>
                         <a href="school_publish.php?school_id=<?=$row->school_id?>&publish=0" class="turn_on" name="turn_on" title="Unpublish"></a>
                        <?php } else { ?> 
                         <a href="school_publish.php?school_id=<?=$row->school_id?>&publish=1" class="turn_off" name="turn_off" title="Publish"></a>
                        <?php } ?>	
                        
                        <a href="school_edit.php?school_id=<?=$row->school_id?>" class="edit" title="Edit">Edit</a> 
                        
                        <a onClick="if (window.confirm('Do you really want to delete this school?\n<?=sth($row->school_name)?>\nThis will also delete all courses for this school!')) { document.location='school_del.php?school_id=<?=$row->school_id?>'; return false; }" class="delete" title="Delete">Delete</a>
                        
                    </td>
                    
                </tr>
                    
			 <?php
                  $i++;    
                } 
             ?>	
		 		  
			</tbody>
		</table>
        
        <div class="pagingwrap"><div class="paging">
			<?=$paging->display()?>
        </div></div>
<?php
	foot_admin(); 
?>